From fe5fac14ca0543b10adff7f198e791069a073f87 Mon Sep 17 00:00:00 2001 From: tsteven4 Date: Thu, 11 Oct 2018 11:28:41 -0600 Subject: [PATCH] correct sort filter time option to use msecs. --- reference/sortfilter_in.gpx | 15 +++++++++++++++ reference/sortfilter_out.gpx | 29 +++++++++++++++++++++++++++++ sort.cc | 8 +++++++- testo.d/sort.test | 9 +++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 reference/sortfilter_in.gpx create mode 100644 reference/sortfilter_out.gpx create mode 100644 testo.d/sort.test diff --git a/reference/sortfilter_in.gpx b/reference/sortfilter_in.gpx new file mode 100644 index 000000000..2fb72cad4 --- /dev/null +++ b/reference/sortfilter_in.gpx @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/reference/sortfilter_out.gpx b/reference/sortfilter_out.gpx new file mode 100644 index 000000000..2feb73b02 --- /dev/null +++ b/reference/sortfilter_out.gpx @@ -0,0 +1,29 @@ + + + + + + + WPT004 + WPT004 + WPT004 + + + + WPT002 + WPT002 + WPT002 + + + + WPT001 + WPT001 + WPT001 + + + + WPT003 + WPT003 + WPT003 + + diff --git a/sort.cc b/sort.cc index a50be2c73..8c096d345 100644 --- a/sort.cc +++ b/sort.cc @@ -25,6 +25,12 @@ #if FILTERS_ENABLED +template +inline int sgn(T v) { +// Returns 1 if v > 0, -1 if v < 0, and 0 if v is zero + return (v > T(0)) - (v < T(0)); +} + int SortFilter::sort_comp(const queue* a, const queue* b) { const Waypoint* x1 = reinterpret_cast(a); @@ -38,7 +44,7 @@ int SortFilter::sort_comp(const queue* a, const queue* b) case sm_description: return x1->description.compare(x2->description); case sm_time: - return x1->GetCreationTime().toTime_t() - x2->GetCreationTime().toTime_t(); + return sgn(x2->GetCreationTime().msecsTo(x1->GetCreationTime())); default: abort(); return 0; /* Internal caller error. */ diff --git a/testo.d/sort.test b/testo.d/sort.test new file mode 100644 index 000000000..cc00b34c0 --- /dev/null +++ b/testo.d/sort.test @@ -0,0 +1,9 @@ +# +# sort filter tests +# + +rm -f ${TMPDIR}/sortfilter* + +gpsbabel -i gpx -f ${REFERENCE}/sortfilter_in.gpx -x sort,time -o gpx -F ${TMPDIR}/sortfilter_out.gpx +compare ${REFERENCE}/sortfilter_out.gpx ${TMPDIR}/sortfilter_out.gpx + -- 2.30.2